package com.qk.management.service.impl;

import com.github.pagehelper.Page;
import com.github.pagehelper.PageHelper;
import com.qk.common.PageResult;
import com.qk.entity.Role;
import com.qk.management.mapper.RoleMapper;
import com.qk.management.service.RoleService;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Service;

import java.util.List;

@Service
public class RoleServiceImpl implements RoleService {
    @Autowired
    private RoleMapper roleMapper;

    @Override
    public PageResult<Role> page(Integer page, Integer pageSize, String name, String label, String remark){
        //开始分页
        PageHelper.startPage(page,pageSize);
        //执行查询
        List<Role> list=roleMapper.list(name,label,remark);
        //数据查询    条件查询列表强转为Page类型
        Page<Role> rs = (Page<Role>) list;
        //数据封装
        return PageResult.<Role>builder()
                .total(Long.valueOf(rs.getTotal()).intValue())
                .rows(rs.getResult())
                .build();
    }

    @Override
    public void deleteById(Integer id) {
        roleMapper.deleteById(id);
    }

    @Override
    public void add(Role role) {
        roleMapper.add(role);
    }

    @Override
    public Role getById(Integer id) {
        return roleMapper.getById(id);
    }

    @Override
    public void update(Role role) {
        roleMapper.update(role);
    }


    @Override
    public List<Role> findAll() {
        return roleMapper.findAll();
    }
}
